import 'package:flutter/material.dart';
import 'package:flutter_house_manager/components/notify_item.dart';
import 'package:flutter_house_manager/utils/TokenManager.dart';
import 'package:flutter_house_manager/utils/toast.dart';

class HomeList extends StatefulWidget {
  const HomeList({super.key, required this.list});
  final List list;

  @override
  State<HomeList> createState() => _HomeListState();
}

class _HomeListState extends State<HomeList> {
  // 头部组件
  Widget getTitleWidget() {
    return Padding(
        padding: const EdgeInsets.all(10),
        child: Row(
          children: [
            Image.asset(
              "assets/images/notice@2x.png",
              width: 25,
              height: 25,
            ),
            const SizedBox(
              width: 5,
            ),
            const Text(
              "社区",
              style: TextStyle(
                  color: Colors.black,
                  fontSize: 16,
                  fontWeight: FontWeight.bold),
            ),
            const Text(
              "公告",
              style: TextStyle(
                  color: Colors.orange,
                  fontSize: 16,
                  fontWeight: FontWeight.bold),
            ),
          ],
        ));
  }

  // 获取列表渲染内容
  Widget getListBuilder(BuildContext context) {
    return ListView(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(), // 禁止滚动
      children: widget.list.map((item) {
        return GestureDetector(
          onTap: () {
            Navigator.pushNamed(context, "/noticeDetail",
                arguments: {"id": item["id"]});
          },
          child: NotifyItem(item: item),
        );
      }).toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [getTitleWidget(), getListBuilder(context)],
    );
  }
}
